package com.chcit.share.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chcit.share.admin.core.http.HttpResult;
import com.chcit.share.admin.core.page.PageRequest;

import com.chcit.share.admin.model.SysDict;
import com.chcit.share.admin.service.SysDictService;

/**
 * ---------------------------
 * 字典表 (SysDictController)         
 * ---------------------------
 * 作者：  share-generator
 * 时间：  2019-04-05 01:48:06
 * 说明：  我是由代码生成器生生成的
 * ---------------------------
 */
@RestController
@RequestMapping("sysDict")
public class SysDictController {

	@Autowired
	private SysDictService sysDictService;

	/**
	 * 保存字典表
	 * @param record
	 * @return
	 */	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysDict record) {
		return HttpResult.ok(sysDictService.save(record));
	}

    /**
     * 删除字典表
     * @param records
     * @return
     */
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody SysDict records) {
		return HttpResult.ok(sysDictService.deleteByDictId(records));
	}

    /**
     * 基础分页查询
     * @param pageRequest
     * @return
     */    
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody PageRequest pageRequest) {
		QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
		Page<SysDict> page = new Page<SysDict>(0, 10);
		IPage<SysDict> pageList = sysDictService.page(page, queryWrapper);
		return HttpResult.ok(pageList);
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@GetMapping(value="/findById")
	public HttpResult findById(@RequestParam Long id) {
		return HttpResult.ok(sysDictService.getById(id));
	}
}
